Page({
    data: {
        params : '' ,
        rudio : '' ,
        question : '',
    },
    onLoad: function (options) {
        let that = this
        that.xInit()
        that.xSystem()
    },

    xToPlay: function (e) {
        let params = e.currentTarget.dataset
        wx.navigateTo({
            url: '/subtool/pages/rudio/detail/index',
            success: function(res) {
              // 通过eventChannel向被打开页面传送数据
              res.eventChannel.emit('xToAudioDetail', params)
            }
        })
    },

    xInit: async function () {
        let that = this
        await wx.cloud.callFunction({
            name : 'order_task_func' ,
            data : {
                action : 'get_muses'
            }
        }).then(res => {
            console.log(res)
            let data = res.result
            that.setData({
                rudio : data
            })
        })
    },

    // 播发结束
    audioended: async function (e) {
        let that = this
        let params = e.currentTarget.dataset
        let question = that.data.question
        if(question[0].recordList.length === 0){
            await wx.cloud.callFunction({
                name : 'order_task_func' ,
                data : {
                    action : 'add_answer_record' ,
                    recordObj : {
                        class_number : question[0].task_class_number ,
                        task_problem_number : question[0].problem_number ,
                        answer : params.key ,
                        content : params.key ,
                    }
                }
            })
        }
    },
    back: function () {
        wx.navigateBack({
            delta: 1 ,
            fail : () => {
                wx.switchTab({
                    url: '/pages/navigation/index/index',
                })
            }
        })
    },
    xSystem: function(){
        let that = this
        wx.getSystemInfo({
            success: (e) => {
                let custom = wx.getMenuButtonBoundingClientRect();
                that.setData({
                    statusBar : e.statusBarHeight,
                    customBar : custom.bottom + custom.top - e.statusBarHeight
                })
            }
        })
    },
})